#!/bin/bash -e

COV_RUSTFLAGS="-Zprofile -Ccodegen-units=1 \
        -Cllvm_args=-inline-threshold=0 -Clink-dead-code \
        -Coverflow-checks=off -Cpanic=abort"

get_crate_name()
{
  while [[ $# -gt 1 ]] ; do
    v=$1
    case $v in
      --crate-name)
        echo $2
        return
        ;;
    esac
    shift
  done
}

case $(get_crate_name "$@") in
    (sgxcovenclave)
    EXTRA=${COV_RUSTFLAGS}
    ;;
  *)
    EXTRA=
    ;;
esac

exec "$@" $EXTRA
